home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / driver.com / HANDLER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-09  |  2.1 KB  |  69 lines

  1. /* 
  2.    This C module can be modified to suit your needs just make sure the 
  3.    initialization routine puts the code segment and end of code address in
  4.    the request header during initialization.
  5. */
  6.  
  7. #define ENDCODE 0x05c2    /* address of end of last segment, can be found by */
  8.             /* linking the modules and then checking the map file */
  9.  
  10. typedef unsigned char Byte;
  11. typedef unsigned int  Word;
  12. typedef struct {
  13.     Byte    length;        /* length of request header */
  14.     Byte    unit;        /* unit code for block devices */
  15.     Byte    command;    /* command code sent by DOS */
  16.     Word    status;        /* status returned from driver code */
  17.     char    reserved[8];    /* reserved by DOS */
  18.     char    data;        /* data from this point is variable */
  19.     Word    endcode;    /* address of end of code needed by init routine */
  20.     Word    segment;    /* code segment of driver */
  21. } RequestHeader;
  22.  
  23.  
  24. int handler(RequestHeader far *rh)
  25. {
  26. char *message = "Device Driver Loading...\n\r\007$";
  27. Word segment;
  28.  
  29.   asm mov ax,DGROUP    /* get data segment of this module */
  30.   asm mov ds,ax        /* you only need this if you are going to use inline */
  31.               /* code and reference local data */
  32.   
  33.   if(rh->command == 0)    /* initialize */
  34.   {
  35.       /* 
  36.        you must put the code segment and end of code address into the
  37.        request header when initializing, this is so DOS knows where to
  38.        start loading the next device driver
  39.     */
  40.       asm mov segment,cs
  41.     rh->endcode = ENDCODE;    
  42.     rh->segment = segment;
  43.     
  44.     asm mov ah,09h        /* the initialization routine is the only */
  45.     asm mov dx,message    /* place you can safely call a DOS function */
  46.     asm int 21h        /* since we're not in the kernel yet */
  47.  
  48.        return 0;
  49.   }
  50.  
  51. /* 
  52.    you can call library functions that don't call DOS and don't need the C
  53.    startup code, just remember to link using the correct memory model
  54.    
  55.    check the DOS programmers ref. for additional commands which DOS might
  56.    pass to the device driver, if you don't have a DOS ref. send me mail and
  57.    I'll upload a list of available commands
  58. */
  59.   sound(10000);
  60.   delay(50);
  61.   sound(20000);
  62.   delay(20);
  63.   nosound();
  64.  
  65.   return 0;
  66.     
  67. }
  68.  
  69.